
const NoteSchema = require('../models/Note.js');
const UserSchema = require('../models/User.js');
const BirdSchema = require('../models/Bird.js');
var { verifyToken } = require('../utils/jsonwebtoken');
const JsonData = require('../Json/bird.json')

module.exports = {
    async addBird(ctx, next) {
        const params = ctx.request.body
        let preData = {
            BirdChineseName: params.BirdChineseName,
            BirdEnglishName: params.BirdEnglishName,
            protectionStatus: params.protectionStatus,
            introduction: params.introduction,
            imgList: params.imgList,
            habitat: params.habitat || '',
            behavior: params.behavior || '',
            character: params.character || '',
            classification: {
                mu: params.classification.mu,
                ke: params.classification.ke
            }
        }
        let res = await BirdSchema.create(preData)
        if (res) {
            ctx.body = {
                success: true,
                msg: `${BirdChineseName} 添加成功`,
            }
        }
    },
    async getBirdsByClassify(ctx, next) {
        const params = ctx.request.body;
        let res = await BirdSchema.find({
            'classification.mu': params.mu,
            'classification.ke': params.ke,
        })
        ctx.body = {
            success: true,

            data: res
        }
    },
    async getBirdById(ctx, next) {
        const params = ctx.request.body;
        let res = await BirdSchema.findById(params.id)

        ctx.body = {
            success: true,

            msg: `${res.BirdChineseName}`,
            data: res
        }
    },
    async getFuzzyquery(ctx, next) {
        const params = ctx.request.body;
        let res = await BirdSchema.find({ "BirdChineseName": { $regex: params.value } })
        ctx.body = {
            success: true,
            data: res
        }
    },
    getSystemBirdInfo(ctx, next) {
        let birdData = JsonData.birdData
        let placeData = JsonData.placeData
        let swipeImgList = JsonData.swipeImgList
        let coupe = JsonData.coupe
        let coupeData = JsonData.coupeData
        ctx.body = {
            success: true,
            birdData,
            placeData,
            swipeImgList,
            coupe,
            coupeData
        }
    }
}